package org.mifos.boss.business;

import java.util.List;

import org.apache.log4j.Logger;
import org.mifos.boss.application.model.UserCredentials;
import org.mifos.boss.domainmodel.ClientCollectionData;
import org.mifos.boss.domainmodel.CollectionSheet;
import org.mifos.boss.persistence.BossPersistenceInterface;
import org.mifos.boss.webservice.RESTclient.RESTClientController;
import org.mifos.boss.webservice.model.ClientDescription;
import org.mifos.boss.webservice.model.CustomerHierarchy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.mifos.boss.webservice.model.CollectionSheetDto;


@Transactional
@Repository(value="bossDeliveryBusiness")
public class BossDeliveryBusinessImpl extends BaseBossBusiness implements BossDeliveryBusinessInterface {

	protected static Logger logger = Logger.getLogger(BossDeliveryBusinessImpl.class);

	@Autowired
	@Qualifier("bossPersistence")
	BossPersistenceInterface bossPersistence;
	
	
	
	public CustomerHierarchy retrieveCustomerHierarchy(UserCredentials user){
		
		RESTClientController mifosClient = prepareUserforRESTcall(user);
		
		if(mifosClient!=null)
			return mifosClient.callRESTCustomerUnderPersonnelService();
		else
			return null;
		
	}
	
	//get loan officer 
	//get all client under this loan officer
	//invoke a rest call for each client with customer id and create clientcustomerdata
	//add all clientcustomerData and create collectionsheet.
	
	
	//it seems one customer call will return complete colelctionsheet data for that hierarchy
	
	public CollectionSheetDto retrieveCollectionSheet(UserCredentials user, String customerId){
		
		RESTClientController mifosClient = prepareUserforRESTcall(user);
		 return mifosClient.callRESTCollectionSheetService(customerId);
		
	}
	
//	public ClientCollectionData retrieveClientCollectionData(RESTClientController mifosClient, int custId){
//			
//		ClientCollectionData clientCollectionData = null;
//		CollectionSheetDto collSheetDto = null;
//		
//		if(mifosClient!=null)
//			
//			collSheetDto = mifosClient.callRESTCollectionSheetService(Integer.toString(custId));
//		else
//			return null;
//		
//		clientCollectionData.setCustomerId(collSheetDto.)
//		
//		return clientCollectionData;
//	}
	
	
}
